import matplotlib.pyplot as plt
import re
def read_txt(inputpath):
    with open(inputpath, 'r', encoding='utf-8') as infile:
        list = []
        lines = infile.readlines()
        for line in lines:
            # 正则匹配数据  只取小数点后面的数
            line = re.findall(r"\d+\.?\d*", line)
            # 数据类型转换
            a = float(line[0])
            # 加入到列表中
            list.append(a)
        return list
if __name__ == "__main__":
    dataV7 = read_txt('epoch_loss.txt')
    dataV5 = [];
    dataV4 = [];
    names = []
    for i in range(0, 60 , 10):
        names.append(i)
    x = range(60)
    plt.rcParams['font.sans-serif'] = ['SimHei']  # 显示汉字
    y_1 = dataV7
    y_2 = dataV5
    y_3 = dataV4
    plt.plot(x, y_1, color='orangered', marker='o', linestyle='-', label='YOLOV7‘ train loss')
    plt.legend()  # 显示图例
    plt.xticks(x, names, rotation=60)
    plt.xlabel("Epoch")  # X轴标签
    plt.ylabel("Train Loss")  # Y轴标签
    plt.show()